package com.ws.test.threaddemo;

/**
 * Created by WUSONG on 2017/12/6.
 */
public class PrintEven implements Runnable{
    private Num num;

    public PrintEven(Num num) {
        this.num = num;
    }

    @Override
    public void run() {
        while (num.i < 100){
           synchronized (num){
               if (!num.flag){
                   try {
                       num.wait();
                   } catch (InterruptedException e) {
                       e.printStackTrace();
                   }
               }else {
                   System.out.println("Thread : "+Thread.currentThread().getName() +"----"+ ++num.i);
                   num.flag = false;
                   num.notify();
               }
           }
        }
    }
}
